<template>
  <div id="app">
    <div id="neirong">
       <!-- 导航栏 -->
    <van-nav-bar title="商品小站登录" left-arrow @click-left="btn" placeholder/>
    <!-- form表单 -->
    <van-form @submit="onSubmit" style="margin-top:20px" />
      <van-field
        name="手机号"
        label="+86"
        v-model="userInfo.mobile"
        placeholder="请输入手机号"
        :rules="userFormRules.mobile"
      />
      <van-field
        name="验证码"
        v-model="userInfo.code"
        placeholder="请输入验证码"
        :rules="userFormRules.code"
      >
        <template #button>
          <van-button size="small" type="primary">发送验证码</van-button>
        </template>
        <template #button>
          <van-count-down
            :time="time"
            format="ss 秒"
            v-if="userInfo.isShowTime"
            @finish="userInfo.isShowTime = false"
          />
          <van-button size="small" v-else @click="sendMsg"
            >发送验证码</van-button
          >
          
        </template>
       
      </van-field> 
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit" color="linear-gradient(to right, #ff6034, #ee0a24)"
          size="large" text="登录" style="font-size:25px" @click="onSubmit"
          ></van-button
        >
      </div>
      <div style="padding:10px 20px;">
        <span><a href="##">账号密码登录</a></span>
      <span style="float:right"><a href="##">忘记密码?</a></span>
      </div>
    </van-form>
    <van-divider style="margin-top:50px">其他方式登录</van-divider>
    <div id="tu"> 
      <div class="tu1">
        <img src="../../assets/images/QQ.png" alt="">
        <p>QQ</p>
      </div>
       <div class="tu1">
        <img src="../../assets/images/微信.png" alt="">
        <p>QQ</p>
      </div>
       <div class="tu1">
        <img src="../../assets/images/苹果.png" alt="">
        <p>QQ</p>
      </div>
    </div>
    <van-checkbox v-model="checked" shape="square" checked-color="#ee0a24" icon-size="15"
    style="margin-top:70px;text-align:center">若您输入的手机号未注册，将为您直接注册，注册即视为同意<p style="color:blue">京东用户注册协议,用户隐私政策</p></van-checkbox>
    </div>
   
  </div>
</template>

<script>
export default {
  name: "PlusIndex",

  data() {
    return {
      checked:true,
      userInfo: {
        
        // 手机号初始化
        mobile: "",
        // 验证码初始化
        code: "",
        // 定义倒计时是否显示的变量
        isShowTime: false,
        // 定义倒计时5秒的初始值
        time: 5000,
      },
      // 定义规则对象
      userFormRules: {
        mobile: [
          { required: true, message: "手机号不能为空" },
          { pattern: /^1[3|5|7|8]\d{9}$/, message: "手机号格式错误" },
        ],
        code: [
          { required: true, message: "验证码不能为空" },
          { pattern: /^\d{6}$/, message: "验证码格式不对" },
        ],
      },
    };
  },

  mounted() {},

  methods: {
    onSubmit: async function () {
      const res = await this.$http.post("login", this.userInfo);
      console.log(res);
      const {
        data: { status },
      } = res;
      if (status != 200) {
        alert("登录失败");
      } else {
        alert("登录成功");
        this.$router.push("/");
      }
    },
    // 发送验证码事件
    sendMsg: function () {
      this.isShowTime = true; //倒计时显示，按钮隐藏
    },
    btn: function () {
      this.$router.push("/my");
    },
  },
};
</script>

<style lang="less" scoped>
#app {
  background-color: white;
  height: 1300px;
  #neirong{
    width: 90%;
    margin: 0 auto;
  }
}
#tu {
  width: 80%;
  margin: 0 auto;
  display: flex;
  justify-content: space-around;
  p{
    text-align: center;
    padding: 15px 0;
    font-size: 20px;
  }
  img {
    width: 80px;
    height: 80px;
    border-radius: 50%;
  }
}
</style>